
const setHttp = require('./request.js').setHttp;

function recharge(data){
  return setHttp(
    `api/bubble/balance/recharge`,
    data,
    'post'
  )
}

// sumMoney 应支付的钱 
function wxPay(amount,formId) {
  return new Promise((resolve, reject) => {
    recharge({ Amount: parseInt(amount * 100), FormId:formId }).then(obj => {
      console.log('充了钱wwwww', obj);
      // 拿订单号
      let res = JSON.parse(obj.WxJsApiParam),
        outTradeNo = obj.OutTradeNo;
      // 支付
      wx.requestPayment({
        'timeStamp': res.timeStamp,
        'nonceStr': res.nonceStr,
        'package': res.package,
        'signType': 'MD5',
        'paySign': res.paySign,
        'success': (res) => {
          resolve();
        },
        'fail': (err) => {
          reject(err);
        }
      })
    }, (err) => {
      // console.log('提示充钱失败或者关闭充钱wwwww');
      reject(err);
    });
  });
}


module.exports = wxPay